package pdd;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main4 {

    public static void main(String[] args) throws Exception{
        BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
        int T = Integer.parseInt(buf.readLine());
        String s;
        String[] ss;
        StringBuilder sb = new StringBuilder();
        for (int t = 0; t < T; t++){
            s = buf.readLine();
            ss = s.split(" ");
            int N = Integer.parseInt(ss[0]);
            int K = Integer.parseInt(ss[1]);
            int D = Integer.parseInt(ss[2]);
            int Q = Integer.parseInt(ss[3]);
            int[] L = new int[K];
            int[] P = new int[K];
            for (int k = 0; k < K; k++){
                s = buf.readLine();
                ss = s.split(" ");
                L[k] = Integer.parseInt(ss[0]);
                P[k] = Integer.parseInt(ss[1]);
            }
            sb.append(lucky(N, K, D, Q, L, P)).append("\n");
        }
        System.out.print(sb.toString());
    }
    public static int lucky(int N, int K, int D, int Q, int[] L, int[] P)
    {
        int[] dalao = new int[N];
        for (int k = 0; k < K; ++k) {
            int left = Math.max(0, P[k] - D);
            int right = Math.min(N - 1, P[k] + D);
            for (int i = left; i <= right; ++i) {
                dalao[i] += L[k];
                if (dalao[i] >= Q)
                    return k;
            }
        }

        return -1;
    }

}
